from pydantic import BaseModel, ConfigDict

from apps.system.schemas import UserMiniOut, VersionSimpleOut
from core.data_types import DatetimeStr


class TestcaseStep(BaseModel):
    num: int
    action: str
    expect: str
    remark: str | None = None
    testcase_id: int | None = None
    version_id: int


class TestcaseStepOut(TestcaseStep):
    model_config = ConfigDict(from_attributes=True)

    id: int | None


class Testcase(BaseModel):
    title: str
    level: str
    status: int = 0
    precondition: str | None = None
    desc: str | None = None
    version_id: int
    max_version_id: int
    caselib_id: int
    catalog_id: int
    create_user_id: int | None = None
    update_user_id: int | None = None

    steps: list[TestcaseStep] = []


class TestcaseSimpleOut(Testcase):
    model_config = ConfigDict(from_attributes=True)

    id: int
    create_time: DatetimeStr
    update_time: DatetimeStr
    create_user: UserMiniOut
    update_user: UserMiniOut
    version: VersionSimpleOut
    max_version: VersionSimpleOut

    steps: list[TestcaseStepOut] = []


class ChangeTestcaseVersion(BaseModel):
    id: int
    version_id: int


class TestcaseVersion(ChangeTestcaseVersion):
    max_version_id: int


class NewTestcaseVersion(TestcaseVersion):
    # id: int
    # version_id: int
    # max_version_id: int

    steps: list[TestcaseStep]


class TestcaseCatalogs(BaseModel):
    catalog_ids: list[int] = []
